package com.anxin.act.task.service;

import com.anxin.act.task.dao.ViewRuTaskDao;
import com.anxin.act.task.entity.ViewRuTask;
import com.anxin.act.utils.ActTaskUtils;
import com.anxin.common.utils.StringUtils;
import com.anxin.framework.web.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * VIEWService业务层处理
 *
 * @author jbs
 * @date 2021-10-24
 */
@Service
public class ViewRuTaskService extends BaseService<ViewRuTaskDao, ViewRuTask>{
    @Autowired
    private ViewRuTaskDao viewRuTaskDao;

    /**
     * 查询VIEW列表
     *
     * @param viewRuTask VIEW
     * @return VIEW
     */
    public List<ViewRuTask> findPage(ViewRuTask viewRuTask){
        startPage();
        return this.findList(viewRuTask);
    }

    /**
     * 查询VIEW列表
     *
     * @param viewRuTask VIEW
     * @return VIEW
     */
    public List<ViewRuTask> findList(ViewRuTask viewRuTask){
        List<ViewRuTask> taskList = new ArrayList<>();
        if (StringUtils.isNotNull(viewRuTask)){
            taskList = viewRuTaskDao.findList(viewRuTask);
        }
        for (ViewRuTask ruTask : taskList) {
            ruTask.intiData();
        }
        return taskList;
    }

    /**
     * 根据用户登录名查询用户待办
     * @param userName
     * @return
     */
    public List<ViewRuTask> findListByUserId(String userName){
        ViewRuTask viewRuTask = new ViewRuTask();
        viewRuTask.setAssignee(userName);
        viewRuTask.setHang("N");
        return viewRuTaskDao.findList(viewRuTask);
    }

    /**
     * 查询当前用户待办个数
     * @return
     */
    public Long findCount(String userId){
        ViewRuTask viewRuTask = new ViewRuTask();
        viewRuTask.setAssigneeList(ActTaskUtils.findEntrustUserName(userId));
        return viewRuTaskDao.findCount(viewRuTask);
    }

}
